package cn.ilikes.tools.nosql.jpa.clients.indexs.index.hadoops;

import java.io.IOException;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.lucene.store.Lock;
import org.apache.lucene.store.LockFactory;

public class HadoopLockFactory extends LockFactory {
	
	private Path lockdirs;

	private FileSystem fileSystem;
	
	

	public HadoopLockFactory( FileSystem fileSystem,Path lockdirs) {
		super();
		this.lockdirs = lockdirs;
		this.fileSystem = fileSystem;
	}

	@Override
	public void clearLock(String lockName) throws IOException {
		
		fileSystem.delete(new Path(lockdirs, lockName), false);
	}

	@Override
	public Lock makeLock(String lockName) {
		
		Lock lock =new HadoopLock(fileSystem,lockdirs,lockName);
		return lock;
	}

}
